package com.drinks.yiniang.ui.activity.user.wish;

import android.support.design.widget.TabLayout;
import android.support.v4.view.ViewPager;
import android.os.Bundle;
import android.view.View;

import com.drinks.yiniang.R;
import com.drinks.yiniang.adapter.viewpager.TabFragmentAdapter;
import com.drinks.yiniang.ui.fragment.user.wish.DrinksWishFragment;
import com.drinks.yiniang.ui.fragment.user.wish.GoodsWishFragment;
import com.drinks.yiniang.ui.fragment.user.wish.ShareWishFragment;
import com.hansen.library.Constants;
import com.hansen.library.ui.activity.BaseTranBarActivity;
import com.hansen.library.ui.fragment.BaseLazyFragment;
import com.hansen.library.listener.OnNavgationBarClickListener;
import com.hansen.library.ui.widget.nav.NavigationBarLayout;

import java.util.ArrayList;
import java.util.List;

/**
 * 心愿单页面
 * @author han
 * @date 2019/09/08
 */
public class WishListActivity extends BaseTranBarActivity implements OnNavgationBarClickListener, TabLayout.OnTabSelectedListener {

    //nav
    private NavigationBarLayout nav_bar_wish_list;
    private TabLayout tab_wish_list;
    private ViewPager vp_wish_list;

    private GoodsWishFragment mGoodsWishFragment;
    private DrinksWishFragment mDrinksWishFragment;
    private DrinksWishFragment mOtherWishFragment;

    private TabFragmentAdapter mTabFragmentAdapter;

    private List<BaseLazyFragment> mFragments;

    private String[] mTabs;

    @Override
    protected void initView() {
        nav_bar_wish_list = findViewById(R.id.nav_bar_wish_list);

        tab_wish_list = findViewById(R.id.tab_wish_list);

        vp_wish_list = findViewById(R.id.vp_wish_list);
    }

    @Override
    protected void initData(Bundle savedInstanceState) {
        mContext = this;

        initTabAndAdapter();
    }

    private void initTabAndAdapter() {
        mTabs = new String[]{getString(R.string.text_collection), getString(R.string.text_my_wine_list), getString(R.string.text_other_create)};

        mFragments = new ArrayList<>(mTabs.length);

        for(int i = 0; i < mTabs.length; i++) {
            tab_wish_list.addTab(tab_wish_list.newTab().setText(mTabs[i]));
        }

        mGoodsWishFragment = GoodsWishFragment.newInstance();
        mDrinksWishFragment = DrinksWishFragment.newInstance(Constants.TYPE_WISH_LIST_WINE);
        mOtherWishFragment = DrinksWishFragment.newInstance(Constants.TYPE_WISH_LIST_OTHER);

        mFragments.add(mGoodsWishFragment);
        mFragments.add(mDrinksWishFragment);
        mFragments.add(mOtherWishFragment);

        //初始化viewpager数据
        mTabFragmentAdapter = new TabFragmentAdapter(getSupportFragmentManager(), mFragments, mTabs);

        vp_wish_list.setOffscreenPageLimit(2);
        vp_wish_list.setAdapter(mTabFragmentAdapter);
        tab_wish_list.setupWithViewPager(vp_wish_list);
    }

    @Override
    protected void initListener() {
        nav_bar_wish_list.setOnNavgationBarClickListener(this);

        tab_wish_list.addOnTabSelectedListener(this);
    }

    @Override
    public void widgetClick(View v) {

    }

    @Override
    public int getTranBarResID() {
        return R.layout.activity_wish_list;
    }

    @Override
    public void onBackClick(View v) {
        finish();
    }

    @Override
    public void onEditClick(View v) {

    }

    @Override
    public void onTabSelected(TabLayout.Tab tab) {

    }

    @Override
    public void onTabUnselected(TabLayout.Tab tab) {

    }

    @Override
    public void onTabReselected(TabLayout.Tab tab) {

    }
}
